<template>
  <ul class="todo-list">
    <!-- completed: 完成的类名 -->
    <li
      v-for="item in showList"
      :key="item.id"
      :class="{ completed: item.isDone }"
    >
      <div class="view">
        <input
          class="toggle"
          type="checkbox"
          :id="item.id"
          v-model="item.isDone"
        />
        <label :for="item.id">{{ item.sentence }}</label>
        <button class="destroy" @click="delList({ id: item.id })"></button>
      </div>
    </li>
  </ul>
</template>

<script>
import { mapState, mapMutations, mapGetters } from "vuex";
export default {
  props: [],
  computed: {
    ...mapState(["list"]),
    ...mapGetters(["showList"]),
  },
  methods: {
    ...mapMutations(["delList"]),
  },
  watch: {
    "$store.state.list": {
      deep: true,
      handler(newVal) {
        localStorage.setItem("todolist", JSON.stringify(newVal));
      },
    },
  },
};
</script>